####################################################################################

mkdir -p ${Titan_path}/maf
mkdir -p ${Titan_path}/mut
mkdir -p ${Titan_path}/chat

####################################################################################
################################### CHAT CCF
#### 1、得到每个样本没有header的maf
cat ${config_path}/tumor_normal.list | grep -v Normal | tr ',' ' ' | xargs -P 10 -i sh -c '
echo {}
sh ${scripts_path}/chat_ccf/TITAN_1_getMaf.sh {}
'

#### 2、得到CHAT输入格式，并注释突变信息
cat ${config_path}/tumor_normal.list  | grep -v Normal | awk -F, '{print $1}' | xargs -P 10 -i sh -c '
echo {}
${Rscript} ${scripts_path}/chat_ccf/TITAN_2_TranChatInput.R {} ${Titan_path}/maf ${config_path}/tumor_normal.list ${Titan_path}/mut
'

#### 3、计算CCF
## 使用最终人工检查的模型
cat ${config_path}/tumor_normal.list  | grep -v Normal | awk -F, '{print $1}' | sort -u | \
xargs -P 10 -i sh -c '
${chat_rscript} ${scripts_path}/chat_ccf/TITAN_3_CHAT.R \
--mCRC_dir ${mCRC_DIR} \
--Sample {} \
--purity_file ${Titan_path}/Purity_titan.final.tsv \
--mut_file ${Titan_path}/mut/{}_Mut.tsv \
--seg_dir ${Titan_path}/FinalModel \
--out_path ${Titan_path}/chat
'
